<style lang="scss" scoped>
    .tab{
       width: 200px;
       height: 50px;
       line-height: 50px;
       display: flex;
       justify-content: space-around;
       background-color: #999; 
       cursor: pointer;
       border: 1px solid #999;
       text-align: center;
       .item,
       .itemActive{
        width: 50%;
       }
       .itemActive{
        background-color: #fff;
       }
    }
</style>
<template>
    <div>
        <div class="tab">
            <div
                @click="type ='home'"
                :class="{
                    item: type != 'home',
                    itemActive: type == 'home'
                }">
                首页
            </div>
            <div
                @click="type = 'catgary'"
                :class="{
                    item: type != 'catgary',
                    itemActive: type == 'catgary'
                }">
                分类
            </div>
        </div>
            <!-- <home v-if="type === 'home'" />
            <catgary v-if="type === 'catgary'"/> -->
            <!-- 
                动态组件 
                <component :is="组件名字">
                    组件名字是哪个组件，就显示哪个组件的视图
            -->
            <!-- 
                组件切换的时候，会重新加载该组件,
                需要一个属性，记录当前组件的状态，
                或者显示该组件的时候，不让该组件重新加载;
                keep-alive组件
                
                组件名字不要包含 keep-alive component 这些名字
             -->
            <keep-alive>
                <component 
                :is="type" 
                :content="'这是首页'"></component>
            </keep-alive>
    </div>
</template>
<script>
import home from './home.vue';
import catgary from './catgary.vue';
export default {
    data() {
        return {
            type: 'home'
        }
    },
    components:{
        catgary,
        home
    }
}
</script>